class Solution(object):
    def camelMatch(self, queries, pattern):
        m = len(pattern)
        def search(word):
            n = len(word)
            left = 0
            right = 0
            while left < n and right < m:
                if word[left] == pattern[right]:
                    left += 1
                    right += 1
                else:
                    if 'A' <= word[left] <= 'Z':
                        return False
                    else:
                        left += 1
            if right == m:
                while left < n:
                    if 'A' <= word[left] <= 'Z':
                        return False
                    left += 1
                return True
            else:
                return False
        out = []
        for word in queries:
            out.append(search(word))
        return out


data = Solution()
queries = ["FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"]
pattern = "FoBa"
print(data.camelMatch(queries, pattern))
